package com.gagakuai.domain.rules;

import java.util.*;

/**
 * @description: 规则组
 * @author: houhong
 * @create: 2024-09-07 11:04
 **/
public class Rules implements Iterable<Rule> {

    private final List<Rule> ruleList = new ArrayList<>();

    public Rules(Set<Rule> setRules) {
        ruleList.addAll(setRules);
    }

    public Rules(Rule... rules) {
        Collections.addAll(this.ruleList, rules);
    }

    public void register(Rule... rules) {

        Objects.requireNonNull(rules);
        for (Rule rule : rules) {
            Objects.requireNonNull(rule);
            this.ruleList.add(rule);
        }
        Collections.sort(this.ruleList);
    }

    public void unregister(Rule... rules) {

        Objects.requireNonNull(rules);
        for (Rule rule : rules) {
            Objects.requireNonNull(rule);
            this.ruleList.remove(rule);
        }
        Collections.sort(this.ruleList);
    }


    @Override
    public Iterator<Rule> iterator() {
        return ruleList.iterator();
    }
}
